﻿package game 
{
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLLoaderDataFormat;
	import flash.text.TextField;
	import fl.controls.*;
	import game.events.EventData;
	import game.exchangeddata.HashTable;
	/**
	 * ...
	 * @author Doan Nguyen Thuy Nha Truc (Bamboo)
	 */
	public class GameRulePanel extends MovieClip
	{
		private var urlRequest:URLLoader;
		
		public var scrollBarRule:UIScrollBar;
		public var txtRuleTf:TextField;
		public var txtCloseTf:TextField;
		public var txtTitlelTf:TextField;
		public var btnCloseRule:SimpleButton;
		
		public function GameRulePanel() 
		{
			hide();
			urlRequest = new URLLoader();
			urlRequest.dataFormat = URLLoaderDataFormat.VARIABLES;
			urlRequest.addEventListener(Event.COMPLETE, hdlCompleteTxt);
			btnCloseRule.addEventListener(MouseEvent.CLICK, hdlEventClick); 
			txtRuleTf.mouseEnabled = false;
			txtTitlelTf.mouseEnabled = false;
			txtCloseTf.mouseEnabled = false;
		}
		
		private function hdlEventClick(e:Event):void 
		{
			hide();
		}
		public function loadTxt(nameTxt:String):void {
			
			trace("loadTxt");
			urlRequest.load(new URLRequest(nameTxt));
			
		}
		
		private function hdlCompleteTxt(e:Event):void 
		{
			txtRuleTf.htmlText = e.target.data[GlobalVariables.ruleContent + GlobalVariables.lang];	
			scrollBarRule.setSize(650, 370);
			scrollBarRule.update();
		}
		
		public function initText(hashTableInfo:HashTable):void {
			txtTitlelTf.text = hashTableInfo.lookupString("ruleMsg");
			txtCloseTf.text = hashTableInfo.lookupString("btnclose");
		}
		
		public function show():void {
			this.visible = true;
		}
		
		public function hide():void {
			this.visible = false;
		}
	}

}